package com.youlu.campus.service.ranking.impl;

import com.alibaba.fastjson.JSON;
import com.youlu.campus.activity.service.UserActivityTaskRankingService;
import com.youlu.campus.service.ranking.entity.UserActivityTaskRanking;
import com.youlu.campus.entity.UserOtherInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@Slf4j
public class RankingServiceImpl {

    @Autowired
    private UserActivityTaskRankingService userActivityTaskRankingService;

    @Async
    public void updateUserOtherInfo(UserOtherInfo userOtherInfo) {
        log.info(":>>> 开始更新用户其他数据排行榜信息:{}", JSON.toJSONString(userOtherInfo));
        if (Objects.isNull(userOtherInfo)
                || StringUtils.isBlank(userOtherInfo.getUserId())
                || StringUtils.isBlank(userOtherInfo.getNickName())
                || StringUtils.isBlank(userOtherInfo.getAvatarUrl())) {
            log.error(":>>> 修改排行榜用户信息错误:参数错误");
            return;
        }
        UserActivityTaskRanking update = new UserActivityTaskRanking();
        update.setUserId(userOtherInfo.getUserId());
        update.setName(userOtherInfo.getNickName());
        update.setImageUrl(userOtherInfo.getAvatarUrl());
        long l = userActivityTaskRankingService.updateByUserId(update);

        log.info(":>>> 修改用户活动排行榜结果:{},:{}", userOtherInfo.getUserId(), l);
    }

}
